package com.desire.controller.base;

import com.desire.bean.base.Product;
import com.desire.bean.common.PageBean;
import com.desire.bean.common.ResultBean;
import com.desire.controller.common.BaseController;
import com.desire.service.base.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author LittleDesire
 * @description
 * @date 2022-05-23 周一 14:13
 * @since 17
 */
@RestController
@Api(tags = "产品管理")
@RequestMapping("/api/product")
public class ProductController extends BaseController {
    @Autowired
    ProductService productService;

    @ApiOperation("保存产品")
    @PostMapping("/save")
    public ResultBean save(@RequestBody @Validated Product product) {
        int rs = productService.save(product);
        return saveResult(rs);
    }

    @ApiOperation("产品列表")
    @PostMapping("/list")
    public ResultBean queryProduct(@RequestBody @Validated Map<String, Object> map) {
        PageBean pageBean = productService.queryProduct(map);
        return success("产品列表", pageBean);
    }
}
